'''
Created on 02/05/2011

@author: Hagut
'''
from Tester import *
import sys

def generate_output(FILE,problem,algo,heuristic,time):
    '''
    @param FILE: pointer to file
    @param problem: problem to run on
    @param algo: pointer to algorithm
    @param heuristic: pointer to heuristic
    @param time: time to run  
    '''           

#    print problem 
    
    try:
#        print "enter"
        optimal_sol, sols, first_sol_time = algo.find(problem, heuristic(problem), time)
#        print "exit"
        if (optimal_sol is None):
            FILE.write("None\n")
        else:
            FILE.write("Found\t")
            FILE.write(str(len(optimal_sol.getPathActions())))
            FILE.write("\t")
            FILE.write(str(len(sols))+"\t")
            FILE.write(str(first_sol_time)+"\t")
            FILE.write("\n")
    except:
        print problem
        print sys.exc_info()
        FILE.write("Error!!!\n")
        '''
        file = open("C:\\Users\\Hagut\\Desktop\\AI\\output_error.txt","a")
        file.write("size:"+str((problem.width,problem.height)))
        file.write("robots:"+str(problem.robots))
        file.write("obstacles:"+str(problem.obstacle_locations))
        file.write("piles:"+str(problem.dirt_locations))
        '''
    
    
        